<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class User
 * Desc  用户中心控制器
 * Create on 2024/10/26 17:31
 * Create by wangyafang
 */

namespace app\api\controller\wddj\trailer;


use app\api\model\wddj\User;
use app\common\controller\Api;

class UserWechat extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['center','get_mobile'];
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\wddj\trailer\UserWechat();
    }

    /**
     * Desc 用户中心
     * Create on 2024/10/26 17:32
     * Create by wangyafang
     */
    public function center()
    {
        if(!$this->request->isGet()) {
            $this->error('请求类型错误');
        }
        $userWechatObj = $this->model->where('user_id',$this->auth->id)->field('id,mobile')->find();

        $driverModel = new \app\api\model\wddj\trailer\Driver();
        $driverObj = $driverModel->where('wechat_id',$userWechatObj['id'])->find();
        $userWechatObj['certification_examine_status'] = (new \app\api\model\wddj\trailer\CertifiedDrivingAgent())->where('wechat_id',$userWechatObj['id'])->value('state');
        $userWechatObj['avatar'] = $driverObj ? wddj_full_url('/assets/addons/wddj/img/driver.png') : wddj_full_url('/assets/addons/wddj/img/user.png');
        //todo 消息数量

        $userWechatObj->hidden(['id']);
        $this->success('请求成功',$userWechatObj);
    }

    /**
     * Desc 获取手机号
     * Create on 2024/11/27 10:36
     * Create by wangyafang
     */
    public function get_mobile()
    {
        $wechat_id = User::getWechatId($this->auth->id);
        $mobile = $this->model->where('id',$wechat_id)->value('mobile');
        $this->success('请求成功',array('mobile'=>$mobile));
    }
}



 